<template>
  <div>
    <FormPanel
      ref="baseInfo"
      :list="initFormBase"
      :cols="1"
      :labelWidth="180"
      formType="edit"
      :isSubmitBtn="false"
    />
    <div style="text-align:center">
      <el-button size="small" type="primary" icon="el-icon-edit" @click="saveDialog">确 定</el-button>
      <el-button size="small"  icon="el-icon-edit" @click="closeDialog">取 消</el-button>
    </div>
  </div>
</template>
<script>
import {dictionary} from '@/utils/dictMixin';
import {auditInventory} from '@/api/partsmanage/inventory/stockInventoryAudit/index';
import { notifyAction } from '@/utils';

export default {
  name: "auditPopup",
  props: {
    value: {
      type: Array,
      required: true,
      default: () => []
    },
    type: {
      type: Number,
      required: true,
      default: null
    },
  },
  mixins: [dictionary],
  data() {
    return {
      formData: {inventoryIds:''},
      initFormBase: this.initFormBaseFun()
    };
  },
  mounted() {
    let data = []
    this.value.forEach(row =>{
      data.push(row.id);
    })
    this.formData.inventoryIds = data.join(",");
  },
  methods: {
    //基本表单信息
    initFormBaseFun() {
      return [
        {
          type: 'TEXT_AREA',
          label: '审核意见',
          fieldName: 'auditOpinion',
          rules: [
            {required: false, trigger: 'change', message: '请输入审核意见'},
          ],
          maxlength:80
        }
      ];
    },
    //保存
    async saveDialog() {
      const [err, data] = await this.$refs.baseInfo.GET_FORM_DATA();
      if(this.type == 2 && (data.auditOpinion == null || data.auditOpinion == undefined || data.auditOpinion == "")){
          notifyAction('请输入审核意见！', 'warning');
          return;
      }
      this.$confirm('确定审核?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(()=>{
        this.formData = Object.assign({}, this.formData, data,{type:this.type});
        auditInventory(this.formData).then(res =>{
          if (res.resultCode === 200) {
            this.$notify.warning({title: '提示信息', message: "操作成功"});
            // 重新加载
            this.closeDialog();
          }
        })
      })
      
    },
    //取消操作
    closeDialog() {
      this.$emit('close');
    }
  }
};
</script>

<style lang="less" scoped>
</style>
